<!--# layout("/common/mallout.html",{"jsBase":"/js/order/orderPay/"}){ -->
<link rel="stylesheet" href="http://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/style/order.css">
<link rel="stylesheet" href="http://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/style/member.css">
<script src="http://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/style/Validform_v5.3.2.js"></script>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>  
<div class="section">
	<div class="payment_box">
	 <input type="hidden" class="orderId " id="orderId" value="${orderId}">
	 <input type="hidden" class="payPassword " id="payPassword" value="">
    	<div class="payment-section-title">支付订单</div>
        <div class="payment-method-con">
        	<ul class="order-info-fl">
                <li>
                	<p style="text-align:center;"><i class="icon"></i></p>
                    <p>订单审核成功，请尽快支付！</p>
                </li>
                 <li>
                    <label>订单号：</label>
                    <span id="payOrderId">
                        
                    </span>
                </li>
                <li>
                    <label>下单时间：</label>
                    <span id="createtime"></span>
                </li>
                <li>
                    <label>订单金额：</label>
                    <span id="payableAmount"></span>
                </li>
                  <li>
                    <label>应付金额：</label>
                    <span><em class="price"><strong id="surplusPayed"></strong></em>元</span>
                </li>
                 
            </ul>
        </div>
    </div>
    
    <!-------------------------------->
    <div class="payment_box">
    	<div class="payment-section-title">支付方式</div>
        <div class="payment-method-con payDepositPrice">
        	<div class="pay_ment_title">
            	<label for="deposit" class="pay_ment_deposit"><i></i>预存款支付</label>
                <input type="radio" name="pay" value="deposit" id="deposit">
            </div>
            <div class="pay_ment_con">
            	<p class="pay_ment_text">
                	<span>您的预存款余额为<strong class="depositPrice"></strong>元</span> <a href="/user/userAdvance/topUp.do" style="text-decoration:none" target="_blank">去充值></a>
                </p>
            </div>
        </div>
         <div class="payment-method-con payScholarship">
        	<div class="pay_ment_title">
            	<label for="scholarship" class="pay_ment_scholarship"><i></i>奖励金支付</label>
                <input type="radio" name="pay" value="scholarship" id="scholarship">
            </div>
            <div class="pay_ment_con">
            	<p class="pay_ment_text">
                	<span>您的奖励金余额为<strong class="scholarshipPrice"></strong>元</span> <span>可抵扣奖励金金额为<strong class="deductionScholarship"></strong>元</span><!-- <a href="/user/userScholarship/topUp.do" style="text-decoration:none" target="_blank">去充值></a> -->
                </p>
            </div>
        </div>
        <div class="payment-method-con">
        	<div class="pay_ment_title">
            	<label>在线支付</label>
                <!-- <input type="radio" name="pay_app">-->
            </div>
            <div class="pay_ment_con">
            	<div class="paycenter_list">
                	<span>
                      <label for="pay_app_id_alipay"><img src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/upload/pc/pay_ioc/pay-123.png" disabled='disabled'></label>
                      <input type="radio" name="pay" value="alipay" id="pay_app_id_alipay" class="action-change-payment_list">
                      <i></i>
                   </span>
                   <span>
                      <label for="pay_app_id_wxpay"><img src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/upload/pc/pay_ioc/pay-456.png" disabled='disabled'></label>
                      <input type="radio" name="pay" value="weixin" id="pay_app_id_wxpay" class="action-change-payment_list">
                      <i></i>
                  </span>
                  <span>
                      <label for="pay_app_id_upacp"><img src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/upload/pc/pay_ioc/pay-567.png" disabled='disabled'></label>
                      <input type="radio" name="pay" value="upacppc" id="pay_app_id_upacp" class="action-change-payment_list">
                       <i></i>
                  </span>
                  <!--  
                  <span>
                      <label for="pay_app_id_xy">信用支付</label>
                      <input type="radio" name="pay" value="upacpxy" id="pay_app_id_xy" class="action-change-payment_list">
                       <i></i>
                  </span>
                  -->
                </div>
            </div>
        </div>
    </div>
    <div class="payment_present"> <button class="payment_submit">立即支付</button> </div>
    <!--------------------------------->
</div>
<!--#} -->
<script>
layui.use(['payment'], function(){
    var quoteOrderListIndex = layui.payment
    quoteOrderListIndex.init();
});

var orderId=$("#orderId").val();
doAjax('/order/popGoDown/getPayOrderInfo.json', 'post', {'orderId':orderId}, function (data) {
	var payOrderResultDto= data.data;
	var costFreight;//运费
	var pmtRandom;//随机立减金额
	var payed=payOrderResultDto.payed;//已支付金额
	
	$('.depositPrice').html("￥"+payOrderResultDto.advance);
	if(payOrderResultDto.scholarship == null){
		scholarship = "0";
	}else{
		scholarship=payOrderResultDto.scholarship;
	}
	$('.scholarshipPrice').html("￥"+scholarship);
	if(Number(scholarship)==0){
		 $('.payScholarship').hide();//奖励金为0
	}
	if(payOrderResultDto.costFreight){
		 costFreight=payOrderResultDto.costFreight;
	}else{
		 costFreight=0;
	}
	if(payOrderResultDto.pmtRandom){
		pmtRandom=payOrderResultDto.pmtRandom;
	}else{
		pmtRandom=0;
	}
	$('#payOrderId').html(orderId);
	$('#createtime').html(payOrderResultDto.createtime);
	var payableAmount=payOrderResultDto.payableAmount+"元";
	if(costFreight!=0||pmtRandom!=0){
		payableAmount+="("
			if(costFreight!=0){
				payableAmount+="含运费:"+costFreight+"元";
			}
			if(pmtRandom!=0){
				payableAmount+="随机立减金额:"+pmtRandom+"元";
			}
			payableAmount+=")"
	}
	$('#payableAmount').html(payableAmount);
	$('#surplusPayed').html(payOrderResultDto.surplusPayed);
	if(payed&&(Number(payed)>0)){
		var payedHtml='<li>'
                   	 +'<label>已支付：</label>'
                  	 + '<span>'+payed+'元</span>'
             		 + ' </li>'
             		 +'<li>';
		$('.order-info-fl').append(payedHtml);
	}
	if(payOrderResultDto.deductionScholarship==0||payOrderResultDto.deductionScholarship=="0"){
		 $('.payScholarship').hide();
	}else{
		$('.deductionScholarship').html(payOrderResultDto.deductionScholarship);
	}
	
	
})
doAjax('/order/orderPay/cannotByScholarship.json','post',{'parentOrderId':orderId},function(res){
	 if(res.code=='200'){
		 if(res.data){
			 $('.payScholarship').hide();//存在不能使用奖励金支付的商品不能使用奖励金
		 }else{
			
		 }
	 }
},''); 
    
doAjax('/order/orderPay/otherMerchantsByOrderId.json','post',{'parentOrderId':orderId},function(res){
	 if(res.code=='200'){
		 
		 if(res.data){
			 $('.payDepositPrice').hide();//第三方店铺,报价商品不能使用预存款
		 }else{
			
		 }
	 }
   },'');
    
$(document).on('click','.gotoTopup',function(){
    var id = setInterval(function () {
    	doAjax('/user/userWallet/getUserWallet.json','post','',function(res){
    		 if(res.code=='200'){
    	    	var userWallet=res.data.userWallet;
    	    	if(!userWallet){
    	    		return false;
    	    	}
    	    	var newAdvance=userWallet.advance;
    	    	if(newAdvance == null){
    	    		newAdvance = "0";
    	    	}
    	    	var oldAdvance=$('.depositPrice').html();
    	    	oldAdvance=oldAdvance.substr(1);
    	    	if(newAdvance!=oldAdvance){
    	    		 clearInterval(id);
    	    		 $('.depositPrice').html("￥"+newAdvance);
    	    	}
    		 }
    	    },'');
    }, 3000)

})


			var isSetPass=false;//是否设置预存款密码
			doAjax('/user/userWallet/isSetPass.json','post','',function(res){
				if(res.code=='200'){
					isSetPass=res.data.result.data;
				}
			},'');
        	//在线支付
        	$(document).on('click','.paycenter_list label',function(){
        		var butclass=$(this).parents('span');
        			if(!butclass.hasClass('atver'))
        			{
        				butclass.addClass('atver');
        				butclass.siblings().removeClass('atver');
        				$(".pay_ment_title label").removeClass('active');
        			}
        	})
        	//奖励金
        	$(document).on('click','.pay_ment_scholarship',function(){
        			if(!$(this).hasClass('active'))
        			{
        				$(this).addClass('active');
        				$(".paycenter_list span").removeClass('atver');
        				$(".pay_ment_deposit").removeClass('active');
        			}	
        			var paymoney=$('#surplusPayed').html();
    				var scholarshipPrice=$('.scholarshipPrice').html();
    				scholarshipPrice=scholarshipPrice.substr(1);
     				if(isSetPass){
 						doAjax('/html/depositPassword.html', 'get', {'password':1}, function (res) {
 		                    $.prompt({
 		                        style: '',
 		                        title: '支付密码输入',
 		                        con: res,
 		                    });
 		                }, '', 'html')
 					}
     				
 					$(document).on('click','.add_sub',function(){
        				 if (!validForm_03.check(false)) {
        	                    $('.invoice_bill li p').show();
        	                    return;
        	                }
        				 var depositPwd=$('.depositPwd').val();
        				 //校验密码是否正确
        				 if(depositPwd){
        					 doAjax('/user/userWallet/checkAdvancePass.json','post',{'payPassword':depositPwd},function(res){
        							if(res.code=='200'){
        								isRight=res.data.result.data;
        								if(isRight){
        								//	$.alert('success',"预存款密码正确！");
        									 $('.popup-btn-close').click();
        									 $('#payPassword').val(depositPwd);
        									 
        								}
        							}
        							if(res.code=='1101'){
        								$.alert('error',"支付密码不正确！");
        								 $('#payPassword').val();
        								 $('.popup-btn-close').click();
        								 $(".pay_ment_scholarship").removeClass('active');
    									return false;
        							}
        						},'');
        				 }
           			 });
        	})
        	//预存款
        	$(document).on('click','.pay_ment_deposit',function(){
        			if(!$(this).hasClass('active'))
        			{
        				$(this).addClass('active');
        				$(".paycenter_list span").removeClass('atver');
        				$(".pay_ment_scholarship").removeClass('active');
        			}	
        			var paymoney=$('#surplusPayed').html();
    				var depositPrice=$('.depositPrice').html();
        			depositPrice=depositPrice.substr(1);
        			if(Number(paymoney)>Number(depositPrice)){
        				$.alert('error',"预存款金额不足！");
        				return false;
        			}
					if(isSetPass){
						doAjax('/html/depositPassword.html', 'get', {'password':1}, function (res) {
		                    $.prompt({
		                        style: '',
		                        title: '支付密码输入',
		                        con: res,
		                    });
		                }, '', 'html')
					}
        			 $(document).on('click','.add_sub',function(){
        				 if (!validForm_03.check(false)) {
        	                    $('.invoice_bill li p').show();
        	                    return;
        	                }
        				 
        				 var depositPwd=$('.depositPwd').val();
        				 //校验密码是否正确
        				 if(depositPwd){
        					 doAjax('/user/userWallet/checkAdvancePass.json','post',{'payPassword':depositPwd},function(res){
        							if(res.code=='200'){
        								isRight=res.data.result.data;
        								if(isRight){
        								//	$.alert('success',"支付密码正确！");
        									 $('.popup-btn-close').click();
        									 $('#payPassword').val(depositPwd);
        								}
        							}
        							if(res.code=='1101'){
        								$.alert('error',"支付密码不正确！");
        								 $('.popup-btn-close').click();
        								 $('#payPassword').val();
        								 $(".pay_ment_deposit").removeClass('active');
    									return false;
        							}
        						},'');
        				 }
        				 
        				
        			 });
        	})
        	$(document).on('click','.payment_submit',function(){
        		var pay_name = $("input[name='pay']:checked").val();
        		if(!pay_name){
        			$.alert('error',"请选择支付方式！");
        			return false;
        		}
        		var paymoney=$('#surplusPayed').html();
    			var payPassword=$('#payPassword').val();
    			var orderId=$('#orderId').val();
    			var deductionScholarship=$('.deductionScholarship').html();
    			deductionScholarship=deductionScholarship.substr(1);
			
        		if(pay_name=="deposit"){//预存款
        			if(!payPassword&&isSetPass){
    					$.alert('error',"请选择正确的支付方式！");
            			return false;
    				}
        			 window.location.href="/order/orderPay/orderPay.do?payType=deposit&orderId="+orderId+"&depositPwd="+payPassword;
        			
        		}else if(pay_name=="scholarship"){
        			if(!payPassword&&isSetPass){
    					$.alert('error',"请选择正确的支付方式！");
            			return false;
    				}
        			if(Number(paymoney)>Number(deductionScholarship)){//奖励金不足以支付订单
							doAjax('/order/orderPay/orderScholarshipPay.json','post',{'orderId':orderId,'payPassword':payPassword},function(res){
								 if(res.code=='200'){
									window.location.href="/order/orderPay/goOrderPay.do?orderId="+orderId;
								 }
							   },'');
						}else{
							 window.location.href="/order/orderPay/orderPay.do?payType=scholarship&orderId="+orderId+"&depositPwd="+payPassword;
						}
        			
        		}else if(pay_name=="weixin"){
        		
        			  $.ajax({
                 		 type: "post",
                 		 url:"/order/orderPay/orderWXPay.json",
                 		 data:{"payType":pay_name,"orderId":orderId},
                 		 headers:{
                 		        "ip":returnCitySN["cip"]
                 		    },
             		    success: function(data){
         	       			var code_url=data.data;
         	       			window.location.href="/order/orderPay/weixinPay.do?code_url="+code_url+"&orderId="+orderId+"&surplusPayed="+paymoney;
         	       		  }               		 
                          });                 
        		}else{
        			window.location.href="/order/orderPay/orderPay.do?payType="+pay_name+"&orderId="+orderId;
        		}
        		
        	})

</script>

